<extend name="Index:base" />
<block name="body">
<div class="hd-menu-list">
    <ul>
        <li><a href="{:U('index',array('type'=>'export'))}">备份数据</a></li>
        <li class="active"><a href="#">还原数据</a></li>
    </ul>
</div>
<table class="hd-table hd-table-list hd-form" id="table_list">
	<thead>
		<tr>
		   <td>备份名称</td>
		   <td>卷数</td>
		   <td>压缩</td>
		   <td>数据大小</td>
		   <td>备份时间</td>
		   <td>状态</td>
		   <td>操作</td>
		</tr>
	</thead>
	<tbody>
		<volist name="list" id="data">
	        <tr>
	            <td>{$data.time|date='Ymd-His',###}</td>
	            <td>{$data.part}</td>
	            <td>{$data.compress}</td>
	            <td>{$data.size|format_bytes}</td>
	            <td>{$key}</td>
	            <td>-</td>
	            <td class="action">
	                <a class="db-import" href="{:U('import',array('time'=>$data['time']))}">还原</a>&nbsp;
	                <a href="javascript:;" onclick="del('{:U('del',array('time'=>$data['time']))}')">删除</a>
	            </td>
	        </tr>
       </volist>
	</tbody>
</table>
<script type="text/javascript">
        $(".db-import").click(function(){
            var self = this, status = ".";
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;
            function success(data){
                if(data.status){
                    if(data.gz){
                        data.info += status;
                        if(status.length === 5){
                            status = ".";
                        } else {
                            status += ".";
                        }
                    }
                    $(self).parent().prev().text(data.info);
                    if(data.part){
                        $.get(self.href, 
                            {"part" : data.part, "start" : data.start}, 
                            success, 
                            "json"
                        );
                    }  else {
                        window.onbeforeunload = function(){ return null; }
                    }
                } else {
                    alert(data.info,'alert-error');
                }
            }
        });

        function del(id) {
            hd_modal({
                width: 400,//宽度
                height: 200,//高度
                title: '提示',//标题
                content: '确定删除吗',//提示信息
                button: true,//显示按钮
                button_success: "确定",//确定按钮文字
                button_cancel: "关闭",//关闭按钮文字
                timeout: 0,//自动关闭时间 0：不自动关闭
                shade: true,//背景遮罩
                shadeOpacity: 0.1,//背景透明度
                success: function () {
                    hd_ajax(id,'', '__SELF__');
                }
            });
        }

    </script>
</block>